from src.init.init_db import db
from src.utils.model import BaseModel


class TypeModel(BaseModel):
    __tablename__ = 'type'

    tid = db.Column(db.BigInteger, primary_key=True)  # 分类id
    name = db.Column(db.String(100), unique=True)  # 分类名称
    fid = db.Column(db.BigInteger, db.ForeignKey('type.tid'), nullable=True)  # 父分类id

    def to_dict(self):
        return {
            "tid": self.tid,
            "name": self.name,
            "fid": self.fid
        }